package com.lineage.data.item_etcitem.add;

import com.add.PeepCard;
import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1MonsterInstance;
import com.lineage.server.model.Instance.L1NpcInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Character;
import com.lineage.server.model.L1Object;
import com.lineage.server.model.L1WeaponSkill;
import com.lineage.server.model.skill.L1BuffUtil;
import com.lineage.server.serverpackets.S_HPUpdate;
import com.lineage.server.serverpackets.S_OwnCharStatus2;
import com.lineage.server.serverpackets.S_Paralysis;
import com.lineage.server.serverpackets.S_SPMR;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SkillSound;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.types.Point;
import com.lineage.server.world.World;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;

public class MagicReel_SpecialMagice extends ItemExecutor {
  private static final Random _random = new Random();
  
  private int _type;
  
  public static ItemExecutor get() {
    return new MagicReel_SpecialMagice();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    L1Character cha;
    int i;
    L1NpcInstance targetNpc;
    int range, dmg2, dmg;
    ArrayList<L1Object> array_list;
    if (pc == null)
      return; 
    if (item == null)
      return; 
    if (pc.isInvisble() || pc.isInvisDelay()) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(281));
      return;
    } 
    L1BuffUtil.cancelAbsoluteBarrier(pc);
    switch (this._type) {
      case 1:
        cha = getTarget(pc, data[0]);
        if (cha == null)
          return; 
        i = 0;
        while (i < 4) {
          cha.onAction(pc);
          i++;
        } 
        pc.sendPacketsX8((ServerBasePacket)new S_SkillSound(pc.getId(), 6509));
        break;
      case 2:
        cha = getTarget(pc, data[0]);
        if (cha == null)
          return; 
        i = 0;
        while (i < 5) {
          cha.onAction(pc);
          i++;
        } 
        pc.sendPacketsX8((ServerBasePacket)new S_SkillSound(pc.getId(), 6509));
        break;
      case 3:
        cha = getTarget(pc, data[0]);
        if (cha == null)
          return; 
        i = 0;
        while (i < 6) {
          cha.onAction(pc);
          i++;
        } 
        pc.sendPacketsX8((ServerBasePacket)new S_SkillSound(pc.getId(), 6509));
        break;
      case 4:
        cha = getTarget(pc, data[0]);
        if (cha == null)
          return; 
        i = 0;
        while (i < 7) {
          cha.onAction(pc);
          i++;
        } 
        pc.sendPacketsX8((ServerBasePacket)new S_SkillSound(pc.getId(), 6509));
        break;
      case 5:
        cha = getTarget(pc, data[0]);
        if (cha == null)
          return; 
        i = 0;
        while (i < 8) {
          cha.onAction(pc);
          i++;
        } 
        pc.sendPacketsX8((ServerBasePacket)new S_SkillSound(pc.getId(), 6509));
        break;
      case 6:
        cha = getTarget(pc, data[0]);
        if (cha == null)
          return; 
        i = 0;
        while (i < 4) {
          cha.onAction(pc);
          i++;
        } 
        pc.sendPacketsX8((ServerBasePacket)new S_SkillSound(pc.getId(), 4394));
        break;
      case 7:
        cha = getTarget(pc, data[0]);
        if (cha == null)
          return; 
        i = 0;
        while (i < 5) {
          cha.onAction(pc);
          i++;
        } 
        pc.sendPacketsX8((ServerBasePacket)new S_SkillSound(pc.getId(), 4394));
        break;
      case 8:
        cha = getTarget(pc, data[0]);
        if (cha == null)
          return; 
        i = 0;
        while (i < 6) {
          cha.onAction(pc);
          i++;
        } 
        pc.sendPacketsX8((ServerBasePacket)new S_SkillSound(pc.getId(), 4394));
        break;
      case 9:
        cha = getTarget(pc, data[0]);
        if (cha == null)
          return; 
        i = 0;
        while (i < 7) {
          cha.onAction(pc);
          i++;
        } 
        pc.sendPacketsX8((ServerBasePacket)new S_SkillSound(pc.getId(), 4394));
        break;
      case 10:
        cha = getTarget(pc, data[0]);
        if (cha == null)
          return; 
        i = 0;
        while (i < 8) {
          cha.onAction(pc);
          i++;
        } 
        pc.sendPacketsX8((ServerBasePacket)new S_SkillSound(pc.getId(), 4394));
        break;
      case 11:
        if (pc.getInventory().checkItem(40308, 5000000L)) {
          pc.sendPackets((ServerBasePacket)new S_SkillSound(pc.getId(), 2244));
          pc.broadcastPacketAll((ServerBasePacket)new S_SkillSound(pc.getId(), 2244));
          pc.setCurrentHp(pc.getCurrentHp() + 300);
          pc.getInventory().consumeItem(40308, 5000000L);
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY生命力恢复了300点，并收取了5000000现金"));
          break;
        } 
        pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY金币不足500W"));
        break;
      case 12:
        if (pc.getInventory().checkItem(40308, 5000000L)) {
          pc.sendPackets((ServerBasePacket)new S_SkillSound(pc.getId(), 2244));
          pc.broadcastPacketAll((ServerBasePacket)new S_SkillSound(pc.getId(), 2244));
          pc.setCurrentMp(pc.getCurrentMp() + 150);
          pc.getInventory().consumeItem(40308, 5000000L);
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY魔力恢复了150点，并收取了5000000现金"));
          break;
        } 
        pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY金币不足500W"));
        break;
      case 13:
        pc.setSkillEffect(8895, 15000);
        pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY环绕着气息击退敌人能力持续15秒"));
        break;
      case 14:
        cha = getTarget(pc, data[0]);
        if (cha == null)
          return; 
        if (_random.nextInt(100) >= 20) {
          pc.sendPackets((ServerBasePacket)new S_ServerMessage(280));
          return;
        } 
        if (L1WeaponSkill.isFreeze(cha))
          break; 
        cha.setSkillEffect(4000, 3000);
        cha.broadcastPacketX8((ServerBasePacket)new S_SkillSound(cha.getId(), 4184));
        if (cha instanceof L1PcInstance) {
          L1PcInstance targetPc = (L1PcInstance)cha;
          targetPc.sendPackets((ServerBasePacket)new S_SkillSound(cha.getId(), 4184));
          targetPc.sendPackets((ServerBasePacket)new S_Paralysis(6, true));
          targetPc.setSkillEffect(4017, 3000);
          break;
        } 
        if (!(cha instanceof L1NpcInstance))
          break; 
        targetNpc = (L1NpcInstance)cha;
        if (!targetNpc.getNpcTemplate().is_boss())
          targetNpc.setParalyzed(true); 
        break;
      case 15:
        cha = getTarget(pc, data[0]);
        if (cha == null)
          return; 
        if (_random.nextInt(100) >= 20) {
          pc.sendPackets((ServerBasePacket)new S_ServerMessage(280));
          break;
        } 
        if (cha instanceof L1PcInstance) {
          L1PcInstance targetPc = (L1PcInstance)cha;
          PeepCard.TeleportPc(pc, (L1Object)targetPc);
          break;
        } 
        if (cha instanceof L1NpcInstance) {
          targetNpc = (L1NpcInstance)cha;
          PeepCard.TeleportPc(pc, (L1Object)targetNpc);
        } 
        break;
      case 16:
        cha = getTarget(pc, data[0]);
        if (cha == null)
          return; 
        if (_random.nextInt(100) >= 30) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY运气不好 没偷到!!"));
          break;
        } 
        if (cha instanceof L1PcInstance) {
          L1PcInstance targetPc = (L1PcInstance)cha;
          PeepCard.TakePc(pc, (L1Object)targetPc);
          break;
        } 
        if (cha instanceof L1NpcInstance) {
          targetNpc = (L1NpcInstance)cha;
          PeepCard.TakePc(pc, (L1Object)targetNpc);
        } 
        break;
      case 17:
        if (pc.hasSkillEffect(8863)) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY目前逆流时间还持续着"));
          return;
        } 
        pc.setSkillEffect(8863, 1800000);
        pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY受到逆流的攻击.强力暴发"));
        pc.sendPackets((ServerBasePacket)new S_SkillSound(pc.getId(), 5010));
        pc.broadcastPacketX10((ServerBasePacket)new S_SkillSound(pc.getId(), 5010));
        break;
      case 18:
        pc.setSkillEffect(8864, 60000);
        pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY武器附加隐毒效果持续60秒"));
        break;
      case 19:
        if (pc.hasSkillEffect(8865)) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY该技能时间尚未消失"));
          return;
        } 
        pc.setSkillEffect(8865, 1800000);
        pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY体能似乎涌出来了"));
        pc.addMaxHp(500);
        pc.sendPackets((ServerBasePacket)new S_HPUpdate(pc.getCurrentHp(), pc.getMaxHp()));
        pc.sendPackets((ServerBasePacket)new S_SkillSound(pc.getId(), 4848));
        pc.broadcastPacketX10((ServerBasePacket)new S_SkillSound(pc.getId(), 4848));
        break;
      case 20:
        if (pc.hasSkillEffect(8866)) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY该技能时间尚未消失"));
          return;
        } 
        pc.setSkillEffect(8866, 900000);
        pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY魔法增压似乎让我魔法增伤不少"));
        pc.addSp(2);
        pc.sendPackets((ServerBasePacket)new S_SPMR(pc));
        pc.sendPackets((ServerBasePacket)new S_SkillSound(pc.getId(), 4601));
        pc.broadcastPacketX10((ServerBasePacket)new S_SkillSound(pc.getId(), 4601));
        break;
      case 21:
        pc.setSkillEffect(8867, 4000);
        pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY强烈的防护罩保护着你"));
        pc.sendPackets((ServerBasePacket)new S_SkillSound(pc.getId(), 5010));
        pc.broadcastPacketX10((ServerBasePacket)new S_SkillSound(pc.getId(), 5010));
        break;
      case 22:
        if (pc.hasSkillEffect(8868)) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY该技能祝福时间尚未消失"));
          return;
        } 
        pc.setSkillEffect(8868, 900000);
        pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY敏捷祝福 环绕全身"));
        pc.addDex(4);
        pc.sendPackets((ServerBasePacket)new S_OwnCharStatus2(pc));
        pc.sendPackets((ServerBasePacket)new S_SkillSound(pc.getId(), 4899));
        pc.broadcastPacketX10((ServerBasePacket)new S_SkillSound(pc.getId(), 4899));
        break;
      case 23:
        if (pc.hasSkillEffect(8869)) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY该技能祝福时间尚未消失"));
          return;
        } 
        pc.setSkillEffect(8869, 900000);
        pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY力量祝福 环绕全身"));
        pc.addStr(4);
        pc.sendPackets((ServerBasePacket)new S_OwnCharStatus2(pc));
        pc.sendPackets((ServerBasePacket)new S_SkillSound(pc.getId(), 4895));
        pc.broadcastPacketX10((ServerBasePacket)new S_SkillSound(pc.getId(), 4895));
        break;
      case 24:
        if (pc.hasSkillEffect(8870)) {
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY该技能祝福时间尚未消失"));
          return;
        } 
        pc.setSkillEffect(8870, 900000);
        pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY智力祝福 环绕全身"));
        pc.addInt(4);
        pc.sendPackets((ServerBasePacket)new S_OwnCharStatus2(pc));
        pc.sendPackets((ServerBasePacket)new S_SkillSound(pc.getId(), 4891));
        pc.broadcastPacketX10((ServerBasePacket)new S_SkillSound(pc.getId(), 4891));
        break;
      case 25:
        pc.setSkillEffect(8871, 5000);
        pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY鲁夫的霸王气.环绕全身"));
        break;
      case 26:
        cha = getTarget(pc, data[0]);
        if (cha == null)
          return; 
        if (cha instanceof L1PcInstance) {
          L1PcInstance targetPc = (L1PcInstance)cha;
          targetPc.setSkillEffect(8872, 5000);
          targetPc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY敌人受到白息之光的诅咒"));
          targetPc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY受到白息之光的逞罚无法使用物品"));
          pc.sendPackets((ServerBasePacket)new S_SkillSound(pc.getId(), 227));
          pc.broadcastPacketX10((ServerBasePacket)new S_SkillSound(pc.getId(), 227));
        } 
        break;
      case 27:
        cha = getTarget(pc, data[0]);
        if (cha == null)
          return; 
        range = 5;
        dmg = 150 + _random.nextInt(200) + 1;
        array_list = World.get().getVisibleObjects((L1Object)cha, 5);
        array_list.add(cha);
        if (cha instanceof L1PcInstance) {
          Iterator<L1Object> iterator = array_list.iterator();
          while (iterator.hasNext()) {
            L1Object tgobj = iterator.next();
            if (tgobj instanceof L1PcInstance) {
              L1PcInstance tgpc = (L1PcInstance)tgobj;
              if (tgpc.isDead())
                continue; 
              if (tgpc.getClanid() == pc.getClanid() && tgpc.getClanid() != 0)
                continue; 
              if (tgpc.getMap().isSafetyZone((Point)tgpc.getLocation()))
                continue; 
              tgpc.receiveDamage((L1Character)pc, dmg, false, false);
              tgpc.broadcastPacketAll((ServerBasePacket)new S_SkillSound(tgpc.getId(), 5653));
            } 
          } 
          break;
        } 
        if (cha instanceof L1NpcInstance) {
          Iterator<L1Object> iterator2 = array_list.iterator();
          while (iterator2.hasNext()) {
            L1Object tgobj = iterator2.next();
            if (tgobj instanceof L1MonsterInstance) {
              L1MonsterInstance tgmob = (L1MonsterInstance)tgobj;
              if (tgmob.isDead())
                continue; 
              tgmob.receiveDamage((L1Character)pc, dmg);
              tgmob.broadcastPacketAll((ServerBasePacket)new S_SkillSound(tgmob.getId(), 5653));
            } 
          } 
        } 
        break;
      case 28:
        pc.setSkillEffect(8873, 5000);
        pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY重击晕眩的能量附加在武器上了"));
        break;
      case 30:
        cha = getTarget(pc, data[0]);
        dmg2 = 200 + _random.nextInt(400) + 1;
        if (cha == null)
          return; 
        if (cha instanceof L1PcInstance) {
          L1PcInstance targetPc2 = (L1PcInstance)cha;
          pc.setCurrentHp((short)(pc.getCurrentHp() / 5));
          targetPc2.receiveDamage((L1Character)pc, dmg2, false, false);
          pc.sendPackets((ServerBasePacket)new S_SystemMessage("\\fY自杀性 牺牲给予强大伤害"));
          targetPc2.sendPackets((ServerBasePacket)new S_SkillSound(targetPc2.getId(), 4594));
          targetPc2.broadcastPacketX10((ServerBasePacket)new S_SkillSound(targetPc2.getId(), 4594));
        } 
        break;
    } 
  }
  
  private final L1Character getTarget(L1PcInstance pc, int targetID) {
    if (targetID == pc.getId() || targetID == 0) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(281));
      return null;
    } 
    L1Object target = World.get().findObject(targetID);
    if (target == null || !(target instanceof L1Character)) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(281));
      return null;
    } 
    return (L1Character)target;
  }
  
  public void set_set(String[] set) {
    try {
      this._type = Integer.parseInt(set[1]);
    } catch (Exception exception) {}
  }
}
